package pojo;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

//用户类
@Data
public class User implements Serializable {
    //用户编号
    private Integer id;
    //用户名
    private String username;
    //性别
    private String sex;
    //年龄
    private Integer age;

    //全参构造
    public User(String  id, String username, String sex, String  age) {
        this.id = Integer.parseInt(id);
        this.username = username;
        this.sex = sex;
        this.age = Integer.parseInt(age);
    }

    //重写equals()方法
    @Override
    public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    User user = (User) o;
    return Objects.equals(id, user.id) &&
            Objects.equals(username, user.username) &&
            Objects.equals(sex, user.sex) &&
            Objects.equals(age, user.age);
    }
    //重写hashCode()方法
    @Override
    public int hashCode() {
        return Objects.hash(id, username, sex, age);
    }

    //重写toString()方法
    @Override
    public String toString() {
        return "用户名:" + username + ", 性别:" + sex + ", 年龄:" + age;
    }
}
